﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TutorCenter.DataAccess.DataContext;
using TutorCenter.DataAccess.Entity;
using TutorCenter.DataAccess.Repository;

namespace TutorCenter.Service.Common
{
    public class EntityService<T> : IEntityService<T> where T : Base
    {   
        private IGenericRepository<T> genericRepository;
        private IUnitOfWork unitOfWork;

        public EntityService(IGenericRepository<T> genericRepository, IUnitOfWork unitOfWork)
        {
            this.genericRepository = genericRepository;
            this.unitOfWork = unitOfWork;
        } 
        public IList<T> GetAll()
        {
            return genericRepository.GetAll().ToList();
        }

        public void Add(T entity)
        {
            genericRepository.Add(entity);
            unitOfWork.Commit();
        }

        public void Edit(T entity)
        {
            genericRepository.Edit(entity);
            unitOfWork.Commit();
        }

        public void Delete(T entity)
        {
            genericRepository.Delete(entity);
            unitOfWork.Commit();
        }
    }
}
